# -*- coding: utf-8 -*-

# __date:       2021/7/13
# __author:     Yang Chao
# __function:

class Solution:

    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:

        res, m = [], len(nums)
        nums.sort()
        for i in range(m):
            for j in range(i + 1, m):
                l, r = j + 1, m - 1
                while l < r:
                    temp = nums[i] + nums[j] + nums[l] + nums[r]
                    if temp == target:
                        if [nums[i], nums[j], nums[l], nums[r]] not in res:
                            res.append([nums[i], nums[j], nums[l], nums[r]])
                        l += 1
                        r -= 1
                    elif temp < target:
                        l += 1
                    else:
                        r -= 1

        return res